/*
 * DirectoryTableModel.java
 *
 * Created on 18 July 2005, 09:18
 * Copyright (C) 2005, Velocityme Partnership
 */

package com.velocityme.client.gui.directory;

import com.velocityme.client.gui.VectorTableModel;
import com.velocityme.utility.DirectoryDTO;
import com.velocityme.valueobjects.LoginValue;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import javax.swing.ImageIcon;

/**
 *
 * @author  Robert Crida Work
 */
public class DirectoryTableModel extends VectorTableModel {
    
    private ImageIcon m_organisationIcon;
    private ImageIcon m_departmentIcon;
    private ImageIcon m_personIcon;

    /** Creates a new instance of SystemPropertyTableModel */
    public DirectoryTableModel(String[] p_columnNames) {
        super(p_columnNames);
        m_organisationIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/organisation-16x16.png"));
        m_departmentIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/department-16x16.png"));
        m_personIcon = new ImageIcon(getClass().getResource("/com/velocityme/client/icons/person-16x16.png"));
    }
    
    public void setDirectoryDTO(DirectoryDTO p_directoryDTO) {
        m_dataRows.clear();
        Iterator i = p_directoryDTO.getRows().iterator();
        while(i.hasNext()) {
            DirectoryDTO.Row row = (DirectoryDTO.Row)i.next();
            Object[] objects = new Object[row.getValues().length + 3];
            switch(row.getType()) {
                case DirectoryDTO.Row.ORGANISATION: objects[0] = m_organisationIcon; break;
                case DirectoryDTO.Row.DEPARTMENT: objects[0] = m_departmentIcon; break;
                default: objects[0] = m_personIcon; break;
            }
            objects[1] = row.getName();
            objects[2] = row.getPath();
            System.arraycopy(row.getValues(), 0, objects, 3, row.getValues().length);
            m_dataRows.addElement(objects);
        }
    }
    
}
